<template>
  <div class="list-special-wrapper-class">
    <el-form :inline="true">
      <el-form-item label="项目名称：">
        <el-input style="width: 150px;" v-model="searchParam.projectName"></el-input>
      </el-form-item>
      <el-form-item label="所属部门：">
        <el-select style="width: 150px;" clearable v-model="searchParam.searchDep" placeholder="请选择">
          <el-option
            v-for="item in departments"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="参与人员：">
        <el-tooltip class="item" effect="dark" :disabled="searchParam.pickedUsersName.length === 0" :content="searchParam.pickedUsersName" placement="bottom">
          <el-input style="width: 150px;" placeholder="请选择" v-model="searchParam.pickedUsersName" :disabled="true"></el-input>
        </el-tooltip>
      </el-form-item>
      <el-button @click="selectDingUsers" style="margin-right:15px;">选择</el-button>
      <el-form-item label="项目状态：">
        <el-select style="width: 150px;" v-model="searchParam.searchStatus" placeholder="请选择">
          <el-option
            v-for="item in kpiStatus"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="searchList(true)">查询</el-button>
        <el-button @click="resetSearch()">重置</el-button>
        <el-button type="primary" v-if="isManager || isGuancha || isTeamer" @click="createProject()">创建项目</el-button>
        <el-button v-if="isManager" type="primary" @click="exportExcel()">导出</el-button>
        <!-- <el-button v-if="isManager" type="primary" @click="showImportProject()">导入项目</el-button> -->
        <el-button v-if="isManager" @click="remindAudit()">提醒审核</el-button>
      </el-form-item>

    </el-form>
    <div>
      <el-table :height="tableHeight" :data="searchResult" border style="width: 100%">
        <el-table-column label="序号" type="index" width="100" align="center"></el-table-column>
        <el-table-column label="所属部门" prop="departmentName" width="130" align="center"></el-table-column>
        <el-table-column label="项目名称" prop="name" min-width="130" align="center"></el-table-column>
        <el-table-column label="项目介绍" prop="remark" min-width="200" align="center"></el-table-column>
        <el-table-column label="发起人" prop="createUserName" width="100" align="center"></el-table-column>
        <el-table-column label="项目状态" width="120" align="center">
          <template slot-scope="scope">
            {{scope.row.status === 0? '未开始': scope.row.status === 100? '已公布': scope.row.status === -100? '已终止': '进行中'}}
          </template>
        </el-table-column>
        <el-table-column label="当前流程" prop="stepName" width="120" align="center">
          <template slot-scope="scope">
            {{scope.row.editLogId ? '内容修改': scope.row.stepName}}
          </template>
        </el-table-column>
        <el-table-column label="项目内容" align="center" min-width="100">
          <template slot-scope="scope">
            <el-button v-if="canedit(scope)" @click="openProject(scope.row.id, false)" type="text" size="small">编辑</el-button>
            <el-button v-if="scope.row.status === 0 && (userInfo.dingId === scope.row.createUserName || isManager || isTeamer)" @click="changeStatus(scope.row)" type="text" size="small">发起</el-button>
            <el-button @click="openProject(scope.row.id)" type="text" size="small">查看</el-button>
            <el-button v-if="scope.row.status >=0 && scope.row.status <=7 && (userInfo.dingId === scope.row.createUserName || isManager)" @click="stopProject(scope.row.processId)" type="text" size="small">终止</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <el-dialog :fullscreen="true" :visible.sync="projectDialog" :show-close="false">
      <div slot="title">
        <h2 style="text-align:center;margin-bottom:0;">时间评估模型</h2>
      </div>
      <div class="status-line">
        <el-steps :active="projectstore.project.status -1" style="margin: 0 auto;">
          <el-step style="cursor: pointer;" title="立项" ></el-step>
          <el-step style="cursor: pointer;" title="内容审核"></el-step>
          <el-step style="cursor: pointer;" title="项目开启"></el-step>
          <el-step style="cursor: pointer;" title="项目完成"></el-step>
          <el-step style="cursor: pointer;" title="质量评分"></el-step>
          <el-step style="cursor: pointer;" title="时间评估"></el-step>
          <el-step style="cursor: pointer;" title="评估终审"></el-step>
        </el-steps>
      </div>
      <div class="form-wrapper">
        <el-button type="info" class="back-btn" icon="el-icon-back" circle @click="projectDialog = false;"></el-button>
        <el-form ref="form" :model="projectstore" label-width="200px">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item style="font-weight: bold;" label="项目名称">
                <el-input :disabled="cantedit" v-model="projectstore.project.name"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item style="font-weight: bold;" label="项目发起人">
                <el-input disabled v-model="projectstore.project.createUserName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item style="font-weight: bold;" label="项目等级">
                <el-select :disabled="cantedit" v-model="projectstore.project.level" placeholder="请选择项目等级">
                  <el-option label="零级" :value="0"></el-option>
                  <el-option label="一级" :value="1"></el-option>
                  <el-option label="二级" :value="2"></el-option>
                  <el-option label="三级" :value="3"></el-option>
                  <el-option label="四级" :value="4"></el-option>
                  <el-option label="五级" :value="5"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item style="font-weight: bold;" label="所属部门">
                <el-select ref="labelSelected" :disabled="cantedit" :readonly="projectCanEdit" v-model="projectstore.project.departmentId" @change="getDeptItem" placeholder="请选择所属部门">
                  <el-option v-for="item in departments" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item style="font-weight: bold;">
                <template slot="label">
                  <el-tooltip placement="bottom" effect="light">
                    <div slot="content">
                      <p><span class="list-special-tip">项目级别</span><span class="list-special-tip">难度级别</span><span class="list-special-tip">电子开发</span><span class="list-special-tip">嵌入式开发</span><span class="list-special-tip">软件开发</span><span class="list-special-tip">结构开发</span></p>
                      <p v-for="item in awardList" :key="item.level"><span class="list-special-tip">{{item.name}}</span><span class="list-special-tip">{{item.level}}</span><span class="list-special-tip">{{item.data1}}</span><span class="list-special-tip">{{item.data2}}</span><span class="list-special-tip">{{item.data3}}</span><span class="list-special-tip">{{item.data4}}</span></p>
                    </div>
                    <div style="cursor:pointer;display:inline-block;margin-left:10px;">项目奖金<i class="el-icon-question"></i></div>
                  </el-tooltip>
                </template>
                <el-input :disabled="cantedit" v-model="projectstore.project.totalBonus"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item style="font-weight: bold;">
                <template slot="label">
                  <el-tooltip placement="bottom" effect="light">
                    <div slot="content">
                      <p><span class="list-special-tip">项目级别</span><span class="list-special-tip">难度级别</span><span class="list-special-tip">电子开发</span><span class="list-special-tip">嵌入式开发</span><span class="list-special-tip">软件开发</span><span class="list-special-tip">结构开发</span></p>
                      <p v-for="item in awardList2" :key="item.level"><span class="list-special-tip">{{item.name}}</span><span class="list-special-tip">{{item.level}}</span><span class="list-special-tip">{{item.data1}}</span><span class="list-special-tip">{{item.data2}}</span><span class="list-special-tip">{{item.data3}}</span><span class="list-special-tip">{{item.data4}}</span></p>
                    </div>
                    <div style="cursor:pointer;display:inline-block;margin-left:10px;">项目积分<i class="el-icon-question"></i></div>
                  </el-tooltip>
                </template>
                <el-input :disabled="cantedit" v-model="projectstore.project.totalPoints"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item style="font-weight: bold;" label="计划开始时间">
                <el-date-picker :disabled="cantedit" type="date" placeholder="选择日期" v-model="projectstore.project.planStartTime" style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item style="font-weight: bold;" label="计划完成时间">
                <el-date-picker :disabled="cantedit" type="date" placeholder="选择日期" v-model="projectstore.project.planEndTime" style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20" v-if="projectstore.project.id">
            <el-col :span="12">
              <el-form-item style="font-weight: bold;" label="实际开始时间">
                <el-date-picker :disabled="cantedit" type="date" placeholder="选择日期" v-model="projectstore.project.startTime" style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item style="font-weight: bold;" label="实际完成时间">
                <el-date-picker :disabled="cantedit" type="date" placeholder="选择日期" v-model="projectstore.project.endTime" style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item style="font-weight: bold;" label="项目参与人员">
            <el-button v-if="!cantedit" @click="addMembers">{{projectstore.members.length === 0 ? '选择人员': '重新选择'}}</el-button>
            <el-table :data="projectstore.members" border style="width: 100%; margin-top:10px;font-weight: normal;">
              <el-table-column label="成员名称" prop="kpiItemKey" min-width="180" align="center">
                <template slot-scope="scope">
                  <div style="white-space: pre-line;">{{scope.row.dingName}}<i v-if="scope.row.manager" class="el-icon-user-solid" style="margin-left:10px;"></i></div>
                </template>
              </el-table-column>
              <el-table-column label="奖励占比" min-width="180" align="center">
                <template slot-scope="scope">
                   <el-input v-if="!cantedit" style="width:100px;" v-model="scope.row.percent"></el-input>
                   <span v-if="cantedit">{{scope.row.percent}}</span>
                   %
                </template>
              </el-table-column>
              <el-table-column v-if="!cantedit" label="操作" align="center" min-width="180">
                <template slot-scope="scope">
                  <i @click="setManager(scope)" class="el-icon-s-flag" style="cursor:pointer;"></i>
                  <i @click="removeMenber(scope)" class="el-icon-remove" style="cursor:pointer;"></i>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item style="font-weight: bold;" label="项目简介">
            <el-input :disabled="cantedit" type="textarea" :autosize="{ minRows: 4}" v-model="projectstore.project.remark"></el-input>
          </el-form-item>
          <el-form-item style="font-weight: bold;" label="考核细则">
            <el-table :data="projectstore.items" border style="width: 100%;font-weight: normal;">
              <el-table-column  label="考核名称" min-width="180" align="center">
                <template slot-scope="scope">
                  <el-select v-if="!cantedit" v-model="scope.row.evItemId" filterable placeholder="请选择" @change="setPoint(scope.row)">
                    <el-option v-for="item in deptItemArr" :key="item.id" :label="item.name" :value="item.id"></el-option>
                  </el-select>
                  <span v-if="cantedit">{{scope.row.evItemName}}</span>
                </template>
              </el-table-column>
              <el-table-column label="考核内容描述" min-width="180" align="left" header-align="center">
                <template slot-scope="scope">
                  <div style="white-space: pre-line;">{{scope.row.evItemContent}}</div>
                </template>
              </el-table-column>
              <el-table-column label="分值倍数" align="center" width="100">
                <template slot-scope="scope">
                  <el-input v-if="!cantedit" v-model="scope.row.scoresPower"></el-input>
                  <span v-if="cantedit">{{scope.row.scoresPower}}</span>
                </template>
              </el-table-column>
              <el-table-column label="评分人" align="center" min-width="120">
                <template slot-scope="scope">
                  <i v-if="scope.row.scoresGiverIds.length === 0 && !cantedit" @click="addAssessor(scope.row)" class="el-icon-circle-plus" style="cursor:pointer;"></i>
                  <span v-if="scope.row.scoresGiverIds.length !== 0 && !cantedit" @click="addAssessor(scope.row)" style="color:#66b1ff;cursor:pointer;">{{scope.row.scoresGiverNames.join(',')}}</span>
                  <i v-if="scope.row.scoresGiverIds.length !== 0 && !cantedit" title="设置相同评分人" class="el-icon-s-order"  style="cursor:pointer;" @click="setSameGiver(scope.$index)"></i>
                  <span v-if="scope.row.scoresGiverIds.length !== 0 && cantedit">{{scope.row.scoresGiverNames.join(',')}}</span>
                </template>
              </el-table-column>
              <el-table-column v-if="!cantedit" label="操作" align="center" width="100">
                <template slot-scope="scope">
                  <i v-if="(projectstore.items.length -1) === scope.$index" @click="addItem(scope)" class="el-icon-circle-plus" style="cursor:pointer;"></i>
                  <i @click="removeItem(scope)" class="el-icon-remove" style="cursor:pointer;"></i>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item style="font-weight: bold;" v-if="changeLog.length > 0" label="项目修改记录">
            <el-table :data="changeLog" border style="width: 100%;font-weight: normal;">
              <el-table-column prop="completeTime" label="日期" min-width="180"> </el-table-column>
              <el-table-column prop="description" label="审核情况" min-width="180">
                <template slot-scope="scope">
                  <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="taskOwnerName" min-width="180" label="审核人"></el-table-column>
              <el-table-column prop="projectRemark" min-width="180" label="审核详情"></el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item v-if="projectstore.project.status > 2 && !isCheck" style="font-weight: bold;" label="备注：">
            当前处于项目进行中，若修改项目内容将中断项目过程并由CEO审核新内容通过后才可能继续进行。
          </el-form-item>
          <el-form-item style="font-weight: bold;" v-if="ApprovalData1.length > 0 && isCheck" label="立项审核记录">
            <el-table :data="ApprovalData1" border style="width: 100%;font-weight: normal;">
              <el-table-column prop="completeTime" label="日期" min-width="180"> </el-table-column>
              <el-table-column prop="description" label="审核情况" min-width="180">
                <template slot-scope="scope">
                  <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="taskOwnerName" min-width="180" label="审核人"></el-table-column>
              <el-table-column prop="projectRemark" min-width="180" label="审核详情"></el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item style="font-weight: bold;" v-if="ApprovalData2.length > 0 && isCheck" label="内容审核记录">
            <el-table :data="ApprovalData2" border style="width: 100%;font-weight: normal;">
              <el-table-column prop="completeTime" label="日期" min-width="180"> </el-table-column>
              <el-table-column prop="description" label="审核情况" min-width="180">
                <template slot-scope="scope">
                  <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="taskOwnerName" min-width="180" label="审核人"></el-table-column>
              <el-table-column prop="projectRemark" min-width="180" label="审核详情"></el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item style="font-weight: bold;" v-if="ApprovalData3.length > 0 && isCheck" label="项目开启记录">
            <el-table :data="ApprovalData3" border style="width: 100%;font-weight: normal;">
              <el-table-column prop="completeTime" label="日期" min-width="180"> </el-table-column>
              <el-table-column prop="description" label="审核情况" min-width="180">
                <template slot-scope="scope">
                  <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="taskOwnerName" min-width="180" label="审核人"></el-table-column>
              <el-table-column prop="projectRemark" min-width="180" label="审核详情"></el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item style="font-weight: bold;" v-if="ApprovalData4.length > 0 && isCheck" label="项目结束记录">
            <el-table :data="ApprovalData4" border style="width: 100%;font-weight: normal;">
              <el-table-column prop="completeTime" label="日期" min-width="180"> </el-table-column>
              <el-table-column prop="description" label="审核情况" min-width="180">
                <template slot-scope="scope">
                  <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="taskOwnerName" min-width="180" label="审核人"></el-table-column>
              <el-table-column prop="projectRemark" min-width="180" label="审核详情"></el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item style="font-weight: bold;" v-if="projectstore.project.status > 5" label="质量评分详情">
            <el-table :summary-method="getSummaries" show-summary :data="projectstore.items" border style="width: 100%;font-weight: normal;">
              <el-table-column label="考核名称" prop="evItemName" min-width="180" align="center"></el-table-column>
              <el-table-column label="考核内容描述" min-width="180" align="left" header-align="center">
                <template slot-scope="scope">
                  <div style="white-space: pre-line;">{{scope.row.evItemContent}}</div>
                </template>
              </el-table-column>
              <el-table-column label="分数" prop="scores" align="center" min-width="80">
                <template slot-scope="scope">
                  <div style="white-space: pre-line;">{{scope.row.scores === ''? '未评分': scope.row.scores}}</div>
                </template>
              </el-table-column>
              <el-table-column label="评分详情" width="150" align="center">
                <template slot-scope="scope">
                  <p v-for="item in scope.row.scoresGivers" :key="item.id">
                    {{item.scoresGiverName}}({{item.scores ? item.scores + '分' : '未评分'}})
                    <el-tooltip placement="bottom" effect="light">
                      <div slot="content">
                        {{item.remark}}
                      </div>
                      <span style="color:#66b1ff;cursor:pointer;"><i class="el-icon-tickets"></i></span>
                    </el-tooltip>
                  </p>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item style="font-weight: bold;" v-if="ApprovalData5.length > 0" label="质量评分记录">
            <el-table :data="ApprovalData5" border style="width: 100%;font-weight: normal;">
              <el-table-column prop="completeTime" label="日期" min-width="180"> </el-table-column>
              <el-table-column prop="description" label="审核情况" min-width="180">
                <template slot-scope="scope">
                  <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="taskOwnerName" min-width="180" label="审核人"></el-table-column>
              <el-table-column prop="projectRemark" min-width="180" label="审核详情"></el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item key="item8" style="font-weight: bold;" v-if="projectstore.project.status === 7 || projectstore.project.status === 100" label="时间评估详情">
            <el-table :data="evaluateDateShowTable" border style="width: 100%;font-weight: normal;">
              <el-table-column min-width="120" prop="name" align="center" label="名称">
                <template slot-scope="scope">
                  <el-tooltip v-if="scope.row.name === '时间评分'" placement="bottom" effect="light">
                    <div slot="content">
                      <p><span class="list-special-tip">逾期得分表</span><span class="list-special-tip">一级</span><span class="list-special-tip">二级</span><span class="list-special-tip">三级</span><span class="list-special-tip">四级</span><span class="list-special-tip">五级</span><span class="list-special-tip">对应项目金</span><span class="list-special-tip">对应积分值</span></p>
                      <p v-for="item in awardList3" :key="item.level"><span class="list-special-tip">{{item.name}}</span><span class="list-special-tip">{{item.data1}}</span><span class="list-special-tip">{{item.data2}}</span><span class="list-special-tip">{{item.data3}}</span><span class="list-special-tip">{{item.data4}}</span><span class="list-special-tip">{{item.data5}}</span><span class="list-special-tip">{{item.data6}}</span><span class="list-special-tip">{{item.data7}}</span></p>
                    </div>
                    <div style="cursor:pointer;display:inline-block;margin-left:10px;">时间评分<i class="el-icon-question"></i></div>
                  </el-tooltip>
                  <el-tooltip v-if="scope.row.name === '最终评分'" placement="bottom" effect="light">
                    <div slot="content">
                      最终奖励取质量得分比和时间得分比最低值
                    </div>
                    <div style="cursor:pointer;display:inline-block;margin-left:10px;">最终评分<i class="el-icon-question"></i></div>
                  </el-tooltip>
                  <span v-if="scope.row.name === '质量评分'">质量评分</span>
                </template>
              </el-table-column>
              <el-table-column min-width="120" align="center" label="奖金">
                <template slot-scope="scope">
                  <span>{{scope.row.percentBonus}}</span>%
                </template>
              </el-table-column>
              <el-table-column min-width="160" align="center" label="积分">
                <template slot-scope="scope">
                  <span>{{scope.row.percentPoints}}</span>%
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item style="font-weight: bold;" v-if="ApprovalData6.length > 0" label="时间评估记录">
            <el-table :data="ApprovalData6" border style="width: 100%;font-weight: normal;">
              <el-table-column prop="completeTime" label="日期" min-width="180"> </el-table-column>
              <el-table-column prop="description" label="审核情况" min-width="180">
                <template slot-scope="scope">
                  <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="taskOwnerName" min-width="180" label="审核人"></el-table-column>
              <el-table-column prop="projectRemark" min-width="180" label="审核详情"></el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item style="font-weight: bold;" v-if="ApprovalData7.length > 0" label="终审记录">
            <el-table :data="ApprovalData7" border style="width: 100%;font-weight: normal;">
              <el-table-column prop="completeTime" label="日期" min-width="180"> </el-table-column>
              <el-table-column prop="description" label="审核情况" min-width="180">
                <template slot-scope="scope">
                  <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="taskOwnerName" min-width="180" label="审核人"></el-table-column>
              <el-table-column prop="projectRemark" min-width="180" label="审核详情"></el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item key="item6" style="font-weight: bold;" v-if="projectstore.project.status === 100" label="奖励明细">
            <el-table :data="projectstore.memberSummary" border style="width: 100%;font-weight: normal;">
              <el-table-column prop="dingName" align="center" label="姓名" min-width="120"> </el-table-column>
              <el-table-column prop="orinBonus" align="center" label="原始项目金" min-width="120"></el-table-column>
              <el-table-column prop="projectBonusPercent" align="center" min-width="120" label="项目金得分">
                <template slot-scope="scope">
                  {{scope.row.projectBonusPercent}}%
                </template>
              </el-table-column>
              <el-table-column prop="finalBonus" align="center" min-width="120" label="实际项目金"></el-table-column>
              <el-table-column prop="orinPoints" align="center" min-width="120" label="原始积分"></el-table-column>
              <el-table-column prop="projectPointsPercent" align="center" min-width="120" label="积分得分">
                <template slot-scope="scope">
                  {{scope.row.projectPointsPercent}}%
                </template>
              </el-table-column>
              <el-table-column prop="finalPoints" align="center" min-width="120" label="实际积分"></el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item>
            <el-button v-if="!cantedit" type="primary" @click="saveProject">{{projectstore.project.id? '保存': '立即创建'}}</el-button>
            <el-button v-if="!cantedit" @click="projectDialog = false;">关闭</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import dingMixin from  '@/mixins/ding'
  import {dateUtil} from '@/utils/dateUtil'
  import * as dd from 'dingtalk-jsapi'
  import formUtil from '@/utils/formUtil'

  export default {
    data () {
      return {
        projectstore: {
          items: [],
          members: [],
          logs: [],
          memberSummary: [],
          project: {
            createTime: '',
            departmentId: '',
            departmentName: '',
            endTime: '',
            id: '',
            initialor: '',
            initialorName: '',
            level: '',
            name: '',
            planEndTime: '',
            planStartTime: '',
            qualityScores: '',
            remark: '',
            startTime: '',
            totalBonus: '',
            totalPoints: ''
          }
        },
        projectVerify: {
          departmentId: '请选择所属部门',
          level: '请选择项目等级',
          name: '请输入项目名称',
          planEndTime: '请选择项目计划完成时间',
          planStartTime: '请选择项目计划开始时间',
          remark: '请输入项目简介',
          totalBonus: '请输入项目奖金',
          totalPoints: '请输入项目积分'
        },
        searchParam: {
          projectName: '',
          searchDep:'',
          pickedUsersName:'',
          pickedUsers: [],
          searchStatus: '',
        },
        projectCanEdit: false,
        ApprovalData1: [],
        ApprovalData2: [],
        ApprovalData3: [],
        ApprovalData4: [],
        ApprovalData5: [],
        ApprovalData6: [],
        ApprovalData7: [],
        projectDialog: false,
        deptItemArr: [],
        departments: [],
        kpiStatus: [{
          value: '',
          label: '全部'
        }, {
          value: '1',
          label: '进行中'
        }, {
          value: '-100',
          label: '已终止'
        }, {
          value: '100',
          label: '已公布'
        }],
        searchResult: [],
        pageSize: 10,
        page:1,
        totalPage: 0,
        isCheck: false,
        awardList:[{
          name: '技术任务',
          level: 0,
          data1: '200-500',
          data2: '200-500',
          data3: '200-500',
          data4: '100-300',
        },{
          name: '变型开发',
          level: 1,
          data1: '800',
          data2: '800',
          data3: '800',
          data4: '400',
        },{
          name: '改进开发',
          level: 2,
          data1: '2000',
          data2: '2000',
          data3: '2000',
          data4: '1000',
        },{
          name: '对标开发',
          level: 3,
          data1: '4000',
          data2: '4000',
          data3: '4000',
          data4: '2000',
        },{
          name: '专项攻关',
          level: 4,
          data1: '6000',
          data2: '6000',
          data3: '6000',
          data4: '3000',
        },{
          name: '高新研发',
          level: 5,
          data1: '8000',
          data2: '8000',
          data3: '8000',
          data4: '4000',
        }],
        awardList2:[{
          name: '技术任务',
          level: 0,
          data1: '2-8',
          data2: '2-8',
          data3: '2-8',
          data4: '2-5',
        },{
          name: '变型开发',
          level: 1,
          data1: '10',
          data2: '10',
          data3: '10',
          data4: '5',
        },{
          name: '改进开发',
          level: 2,
          data1: '15',
          data2: '15',
          data3: '15',
          data4: '10',
        },{
          name: '对标开发',
          level: 3,
          data1: '25',
          data2: '25',
          data3: '25',
          data4: '15',
        },{
          name: '专项攻关',
          level: 4,
          data1: '40',
          data2: '40',
          data3: '40',
          data4: '20',
        },{
          name: '高新研发',
          level: 5,
          data1: '60',
          data2: '60',
          data3: '60',
          data4: '30',
        }],
        awardList3:[{
          name: '一般逾期',
          data1: '≤5%',
          data2: '≤5%',
          data3: '≤8%',
          data4: '≤10%',
          data5: '≤15%',
          data6: '不高于80%',
          data7: '不高于50%'
        },{
          name: '严重逾期',
          data1: '≤15%',
          data2: '≤15%',
          data3: '≤20%',
          data4: '≤25%',
          data5: '≤30%',
          data6: '不高于30%',
          data7: '0'
        },{
          name: '项目事故',
          data1: '>15%',
          data2: '>15%',
          data3: '>20%',
          data4: '>25%',
          data5: '>30%',
          data6: '0',
          data7: '负'
        }],
        changeLog: [],
        evaluateDateShowTable: [],
        tableHeight: window.tableHeight
      }
    },
    computed: {
      isManager() {
        return this.userInfo.roleIdList && this.userInfo.roleIdList.includes('1247700573888290817')
      },
      isTeamer() {
        return this.userInfo.roleIdList && this.userInfo.roleIdList.includes('1321365196464197633')
      },
      isNormal() {
        return this.userInfo.roleIdList && this.userInfo.roleIdList.includes('1321366856351617026')
      },
      isGuancha() {
        return this.userInfo.roleIdList && this.userInfo.roleIdList.includes('1301793232233959426')
      },
      cantedit() {
        return this.isCheck
      }
    },
    activated() {
      this.tableHeight = document.documentElement['clientHeight'] - 250
      window.onresize = () => {
        this.tableHeight = document.documentElement['clientHeight'] - 250
      }
    },
    mixins: [dingMixin, dateUtil],
    async mounted(){
      let deptList = await this.$httpN.get('sys/dept/list')
      if(!this.isManager && !this.isGuancha) {
        this.departments = deptList.filter((item) => item.id === this.userInfo.departmentIds)
      }else {
        this.departments = deptList;
      }
      await this.searchList();
      let defalutProjectId = this.$route.query.projectId;
      if(defalutProjectId) {
        this.openProject(defalutProjectId);
      }else {
        let id = this.$route.params.id;
        if(id) this.openProject(id);
      }
    },
    methods: {
      canedit(scope) {
        return !scope.row.editLogId && (scope.row.status === 0 || scope.row.status === 1 || scope.row.status === 2 || scope.row.status === 3 || scope.row.status === 4 || (scope.row.status === 5 && !scope.row.scored)) && (this.userInfo.dingId === scope.row.createUserName || this.isManager || this.isTeamer)
      },
      addMembers() {
        this.complexPicker(15, []).then((data)=>{
          this.projectstore.members = [];
          data.forEach((item, idx) => {
            this.projectstore.members.push({
              dingId: item.emplId,
              dingName: item.name,
              manager: false,
              percent: 0,
            })
          })
        })
      },
      setManager(scope) {
        this.projectstore.members.forEach((item) => {item.manager = false});
        scope.row.manager = true;
      },
      removeMenber(scope){
        let idx = scope.$index;
        this.projectstore.members.splice(idx,1);
      },
      remindAudit(){
        this.$httpN.postQ('pde/project/noticeTaskOwner');
      },
      async getDeptItem(deptId) {
        let data = await this.$httpN.postB('pde/item/list', {
          'deptId': deptId,
          'withPublic': true,
          'page': 1,
          'limit': 200
        })
        this.deptItemArr = data.list;
      },
      showImportProject(){
        this.searchList(true, 0)
      },
      createProject() {
        let initialProject = {
          items: [{
            evItemContent: '',
            evItemId: '',
            evItemName: '',
            scoresGiverIds: [],
            scoresPower: 0
          },{
            evItemContent: '',
            evItemId: '',
            evItemName: '',
            scoresGiverIds: [],
            scoresPower: 0
          },{
            evItemContent: '',
            evItemId: '',
            evItemName: '',
            scoresGiverIds: [],
            scoresPower: 0
          },{
            evItemContent: '',
            evItemId: '',
            evItemName: '',
            scoresGiverIds: [],
            scoresPower: 0
          }],
          members: [],
          project: {
            departmentId: '',
            departmentName: '',
            endTime: '',
            createUserId: this.userInfo.dingId,
            createUserName: this.userInfo.realName,
            level: '',
            name: '',
            planEndTime: '',
            planStartTime: '',
            remark: '',
            startTime: '',
            totalBonus: '',
            totalPoints: '',
            status: 0
          }
        }
        this.ApprovalData1 = [];
        this.ApprovalData2 = [];
        this.ApprovalData3 = [];
        this.ApprovalData4 = [];
        this.ApprovalData5 = [];
        this.ApprovalData6 = [];
        this.ApprovalData7 = [];
        this.changeLog = [];
        this.projectstore = initialProject;
        this.isCheck = false;
        this.projectDialog = true;
      },
      async openProject(id, isCheck = true) {
        this.isCheck = isCheck;
        let projectstore = await this.$httpN.postQ('pde/project/detail', {projectId: id, withLog: true});
        projectstore.items.forEach((item) => {
          item.scoresGiverNames = item.scoresGivers.map(user => user.scoresGiverName)
        })
        if(projectstore.items.length===0){
          projectstore.items = [{
            evItemContent: '',
            evItemId: '',
            evItemName: '',
            scoresGiverIds: [],
            scoresPower: 0
          },{
            evItemContent: '',
            evItemId: '',
            evItemName: '',
            scoresGiverIds: [],
            scoresPower: 0
          },{
            evItemContent: '',
            evItemId: '',
            evItemName: '',
            scoresGiverIds: [],
            scoresPower: 0
          },{
            evItemContent: '',
            evItemId: '',
            evItemName: '',
            scoresGiverIds: [],
            scoresPower: 0
          }]
        }

        if(projectstore.project.processId) {
          let result = await this.$httpN.postB('pde/project/listAuditTask',{
            'projectId': projectstore.project.id
          })

          let history = result.list;
          this.ApprovalData1 = history.filter(item => item.stepSort === '1' && item.taskStatus !== '0' && item.modelId === '4');
          this.ApprovalData2 = history.filter(item => item.stepSort === '2' && item.taskStatus !== '0' && item.modelId === '4');
          this.ApprovalData3 = history.filter(item => item.stepSort === '3' && item.taskStatus !== '0' && item.modelId === '4');
          this.ApprovalData4 = history.filter(item => item.stepSort === '4' && item.taskStatus !== '0' && item.modelId === '4');
          this.ApprovalData5 = history.filter(item => item.stepSort === '5' && item.taskStatus !== '0' && item.modelId === '4');
          this.ApprovalData6 = history.filter(item => item.stepSort === '6' && item.taskStatus !== '0' && item.modelId === '4');
          this.ApprovalData7 = history.filter(item => item.stepSort === '7' && item.taskStatus !== '0' && item.modelId === '4');
          this.changeLog = history.filter(item => item.stepSort === '1' && item.taskStatus !== '0' && item.modelId === '5');
        }else {
          this.ApprovalData1 = [];
          this.ApprovalData2 = [];
          this.ApprovalData3 = [];
          this.ApprovalData4 = [];
          this.ApprovalData5 = [];
          this.ApprovalData6 = [];
          this.ApprovalData7 = [];
          this.changeLog = [];
        }

        if(projectstore.project.status >= 6) {
          let score = projectstore.project.finalScores ? projectstore.project.finalScores:
                         projectstore.project.overDay === '0'? projectstore.project.qualityScores : ''

          this.evaluateDateShowTable = [{
            name: '质量评分',
            percentPoints: score,
            percentBonus: score,
            edit: false
          },{
            name: '时间评分',
            percentPoints: projectstore.project.percentPoints,
            percentBonus: projectstore.project.percentBonus,
            edit: false
          },{
            name: '最终评分',
            percentPoints: score > projectstore.project.percentPoints? projectstore.project.percentPoints: score,
            percentBonus: score > projectstore.project.percentBonus? projectstore.project.percentBonus: score,
            finalScores: score,
            edit: true
          }]
        }

        if(projectstore.project.status >= 7) projectstore.memberSummary = [...projectstore.members, projectstore.memberSummary];
        if(!isCheck) {
          let data = await this.$httpN.postB('pde/item/list', {
            'deptId': projectstore.project.departmentId,
            'withPublic': true,
            'page': 1,
            'limit': 200
          })
          this.deptItemArr = data.list;
        }
        this.projectstore = projectstore;
        this.projectDialog = true;
      },
      async changeStatus(item) {
        formUtil.submitConfirm('您确定要发起项目立项吗？', async ()=> {
          if(!await this.$httpN.postB('flow/process/start', {
            name: item.name,
            remark: item.remark,
            initiator: this.userInfo.dingId,
            initiatorName: this.userInfo.realName,
            modelId: '4',
            exData: {
              projectId: item.id
            }
          })) return;
          formUtil.submitSuccess('发起审核成功');
          this.searchList();
        })
      },
      resetSearch() {
        this.searchParam = {
            projectName: '',
            searchDep:'',
            pickedUsersName:'',
            pickedUsers: [],
            searchStatus: ''
        }
      },
      selectDingUsers(){
        this.complexPicker(300, [], this.searchParam.pickedUsers).then((data)=>{
          this.searchParam.pickedUsers = data.map(item => item.emplId);
          let names = data.map(item => item.name);
          this.searchParam.pickedUsersName = names.join(',');
        })
      },
      setSameGiver(idx) {
        this.projectstore.items[idx+1].scoresGiverIds = [...this.projectstore.items[idx].scoresGiverIds];
        this.projectstore.items[idx+1].scoresGiverNames = [...this.projectstore.items[idx].scoresGiverNames];
      },
      addAssessor(currentRow) {
        this.complexPicker(5, [], currentRow.scoresGiverIds).then((data)=>{
          currentRow.scoresGiverIds = data.map(item => item.emplId);
          currentRow.scoresGiverNames = data.map(item => item.name);
        })
      },
      async stopProject(id) {
        formUtil.submitConfirm('您确定要终止时间评估吗？', async ()=> {
          if(!await this.$httpN.postQ('flow/process/cancel', {processId: id})) return;
          formUtil.submitSuccess('终止成功');
          this.searchList();
        })
      },
      getSummaries(param) {
        const { columns, data } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '总分';
            return;
          }else if(index === 2) {
            sums[index] = this.projectstore.project.qualityScores;
            return;
          }
        });
        return sums;
      },
      sizeChangeHandle(limit) {
        this.pageSize = limit;
        this.searchList(true);
      },
      currentChangeHandle(page) {
        this.page = page;
        this.searchList();
      },
      async searchList(init) {
        if(init) {
          this.page = 1;
        }
        let data = await this.$httpN.postB('pde/project/list', {
          'deptId': this.searchParam.searchDep,
          'status': this.searchParam.searchStatus,
          'projectName': this.searchParam.projectName,
          'memberId': this.searchParam.pickedUsers.join(','),
          'flag': 1,
          'page': this.page,
          'limit': this.pageSize
        })
        this.searchResult = data.list;
        this.totalPage = data.totalCount;
      },
      setPoint(row) {
        this.deptItemArr.forEach((item) => {
          if(item.id === row.evItemId) {
            row.evItemContent = item.content;
            row.scoresPower = item.scoresPower;
            row.evItemName = item.name;
          }
        })
      },
      removeItem(scope) {
        let idx = scope.$index;
        this.projectstore.items.splice(idx,1)
      },
      addItem(scope) {
        let idx = scope.$index;
        this.projectstore.items.splice(idx+1, 0, {
          evItemContent: '',
          evItemId: '',
          evItemName: '',
          scoresGiverIds: [],
          scoresPower: 0
        })
      },
      async saveProject() {
        if(!formUtil.verifyData(this.projectstore.project, this.projectVerify)) return;
        if(isNaN(this.projectstore.project.totalBonus)) return this.$message.error('项目奖金格式错误');
        if(isNaN(this.projectstore.project.totalPoints)) return this.$message.error('项目积分格式错误');
        if(this.projectstore.members.length === 0) return this.$message.error('请选择项目成员');
        let memberVeryfy = false;
        let count = 0;
        let hasOwner = false;
        this.projectstore.members.forEach((item) => {
          if(!isNaN(item.percent)) {
            count += parseInt(item.percent);
          }else {
            memberVeryfy = true;
          }
          if(item.manager) hasOwner = true;
        })
        if(memberVeryfy) return this.$message.error('项目成员奖励比例格式错误');
        if(!hasOwner) return this.$message.error('项目成员中应有一个管理员');
        if(count !== 100) return this.$message.error('项目成员奖励比例总和应为100');
        this.projectstore.project.departmentName = this.$refs['labelSelected'].selectedLabel;
        let notice = [];
        this.projectstore.items.forEach((item, idx) => {
          if(item.evItemId && item.scoresGiverIds.length === 0) notice.push(idx + 1);
        })
        if(notice.length > 0) return this.$message.error(`第${notice.join(',')}题还未设置评分人`);
        if(!await this.$httpN.postB('pde/project/save', this.projectstore)) return;
        this.projectDialog = false;
        formUtil.submitSuccess('创建成功');
        this.searchList();
      },
      async exportExcel() {
        let fileData = await this.$httpN.get('pde/project/exportExcel', {}, 'blob');
        this.downFile(fileData, `项目考评列表.xls`);
      },
      downFile(blob, fileName) {
        if (window.navigator.msSaveOrOpenBlob) {
          navigator.msSaveBlob(blob, fileName);
        } else {
          var link = document.createElement('a');
          link.href = window.URL.createObjectURL(blob);
          link.download = fileName;
          link.click();
          window.URL.revokeObjectURL(link.href);
        }
      }
    }
  }
</script>
<style lang="scss">
  .list-special-wrapper-class .el-select.el-select--medium{
    width: 100%;
  }
  .list-special-wrapper-class{
    .form-wrapper{
      width: 70%;
      min-width: 1130px;
      margin: 0 auto;
      padding: 70px;
      padding-top: 10px;
      padding-left:0;
      position:relative;
    }
    .status-line{
      height: 80px;
      width: 70%;
      min-width: 1130px;
      padding-top: 10px;
      margin: 0 auto;
      position: sticky;
      top: 0px;
      z-index: 2;
      background-color: white;
    }
    .notice{
      margin-top:10px;
      color:red;
      padding-left:120px;
    }
    .back-btn{
      position: fixed;
      top: 50px;
      left: 50px;
      z-index: 999;
    }

  }

  .list-special-tip{
    display: inline-block;
    width:70px;
    text-align: center;
  }

  @media screen and (max-width:1600px){
    .list-special-wrapper-class .status-line{
      right: 100px;
    }
  }


  @media screen and (max-width:1450px){
    .list-special-wrapper-class .status-line{
      right: 30px;
    }
  }

  .el-step__head.is-process{
    color:#f98911;
    border-color: #f98911;
  }
  .el-step__title.is-process{
    color: #f98911;
  }

  .el-step__head.is-wait{
    color:black;
    border-color: black
  }
  .el-step__title.is-wait{
    color: black;
  }
</style>
